package com.xxx.config;

import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

/**
 * @ClassName: LongToStringMapper 
 * @Description: 解决long类型转json时 丢失精度问题,
 * 	 序列换成json时,将所有的long变成string,
 * 	 因为js中得数字类型不能包含所有的java long值
 */
@SuppressWarnings("serial")
@Configuration
public class LongToStringMapper extends ObjectMapper {
	
	public LongToStringMapper() {
		SimpleModule simpleModule = new SimpleModule();
		simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
		simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
		super.registerModule(simpleModule);
	}
}
